<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;
use \Common\Model\Cate;
use \Common\Model\Brand;
//测试控制器
class IndexController extends Controller{
    //动作
    public function index(){
    	//1.判断是否有用户登录
    	if(isset($_SESSION['user'])){
    		$user = $_SESSION['user'];
			View::with('user',$user);		
    	}

    	//2.获取顶级分类(导航条)
    	$cateModel = new Cate;  
    	// ==>顶级分类
		$topCate = $cateModel->where("pid=0")->orderBy('sort','ASC')->get();
		//重组数组，便于前台数组遍历
		foreach($topCate as $k=>$v){
			//新增字段 son 	==> 一级分类
			$topCate[$k]['son'] = $cateModel->where('pid',$v['cid'])->orderBy('sort','ASC')->get();
			foreach($topCate[$k]['son'] as $kk=>$vv){
				//新增字段 grandson 	==> 二级分类
				$topCate[$k]['son'][$kk]['grandson']=$cateModel->where('pid',$vv['cid'])->orderBy('sort','ASC')->get();
			}
		}		
		View::with('topCate',$topCate);

		//3.获取品牌
		$brandModel = new Brand;
		$brandDataBig = $brandModel->get();
		//获取原图
		foreach($brandDataBig as $k=>$v){
			$brandDataBig[$k]['logo'] = str_replace('_logo', '',$v['logo']);
		}
		View::with('brandDataBig',$brandDataBig);
		//楼层品牌
		$brandData = $brandModel->get();
		View::with('brandData',$brandData);
	
		/*购物车*/
		//先开启$_SESSION['cart']
		Cart::getGoods(); 
		//购物车商品总数
		$goodsNum = Cart::getTotalNums();	
		View::with('goodsNum',$goodsNum);
			
    	View::make();
    }
}
